#ifndef __Noise__
#define __Noise__

#include <vector>
#include "vector.h"
#include "box.h"
class Noise{
protected:
public:
	Noise(){}
  virtual ~Noise() {}
  virtual double Index(const Vector&) const;
private:
  static double RTable[267];
  static short hashTable[4096];

  double IncrSum(int m,double s,double x,double y,double z);
  double IncrSumP(const double *mp,double s,double x,double y,double z) const;
  // Hash code
  inline short Hash1d(int a,int b) const{
    return hashTable[(int)(a) ^ ((b) & 0xfffL)];
  }

  inline short Hash2d(int a,int b) const{
    return hashTable[(int)(hashTable[(int)((a) & 0xfffL)] ^ ((b) & 0xfffL))];
  }
};

//! Internal function
inline double Noise::IncrSum(int m,double s,double x,double y,double z){
	return s*(RTable[m]*0.5+RTable[m+1]*x+RTable[m+2]*y+RTable[m+3]*z);
}

//! Internal function
inline double Noise::IncrSumP(const double *mp,double s,double x,double y,double z) const{
	return s*(mp[0]*0.5+mp[1]*x+mp[2]*(y)+mp[3]*z);
}

class Turbulence:public Noise {
protected:
	double omega;
	double lambda;
	int octaves;
public:
	Turbulence(const double& =2.0,const double& =0.5,int =8);
  //! Destroys a turbulence instance.
	~Turbulence() {}
	double Index(const Vector&) const;
};
#endif
